/*--------------------------------------------------------------------
 * execParallel.h
 *		POSTGRES并行执行接口
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * IDENTIFICATION
 *		src/include/executor/execParallel.h
 *--------------------------------------------------------------------
 */

#ifndef EXECPARALLEL_H
#define EXECPARALLEL_H

#include "access/parallel.h"
#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
#include "utils/dsa.h"

typedef struct SharedExecutorInstrumentation SharedExecutorInstrumentation;

typedef struct ParallelExecutorInfo
{
	PlanState  *planstate;		/* 我们在并行运行的计划子树 */
	ParallelContext *pcxt;		/* 我们使用的并行上下文 */
	BufferUsage *buffer_usage;	/* 指向 DSM 中的 bufusage 区域 */
	WalUsage   *wal_usage;		/* DSM 中的 walusage 区域 */
	SharedExecutorInstrumentation *instrumentation; /* 可选 */
	struct SharedJitInstrumentation *jit_instrumentation;	/* 可选 */
	dsa_area   *area;			/* 指向 DSM 中的 DSA 区域 */
	dsa_pointer param_exec;		/* 序列化的 PARAM_EXEC 参数 */
	bool		finished;		/* 由 ExecParallelFinish 设置为 true */
	/* 这两个数组具有 pcxt->nworkers_launched 的条目： */
	shm_mq_handle **tqueue;		/* 工作线程输出的元组队列 */
	struct TupleQueueReader **reader;	/* 元组读取器/写入器支持 */
} ParallelExecutorInfo;

extern ParallelExecutorInfo *ExecInitParallelPlan(PlanState *planstate,
												  EState *estate, Bitmapset *sendParam, int nworkers,
												  int64 tuples_needed);
extern void ExecParallelCreateReaders(ParallelExecutorInfo *pei);
extern void ExecParallelFinish(ParallelExecutorInfo *pei);
extern void ExecParallelCleanup(ParallelExecutorInfo *pei);
extern void ExecParallelReinitialize(PlanState *planstate,
									 ParallelExecutorInfo *pei, Bitmapset *sendParam);

extern void ParallelQueryMain(dsm_segment *seg, shm_toc *toc);

#endif							/* EXECPARALLEL_H */
